import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

import '../../../config/route/bt_app_router.gr.dart';
import '../../../data/models/bt_goods.dart';
import '../models/bt_coin_shop_model.dart';

class BtGoodsItemWidget extends StatelessWidget {
  const BtGoodsItemWidget({super.key, required this.index, required this.item, required this.model});

  final int index;

  final BtGoods item;

  final BtCoinShopModel model;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      child: Stack(
        children: [
          Container(
            padding: const EdgeInsets.only(left: 22, top: 25, bottom: 25, right: 15),
            decoration: BoxDecoration(
              color: Colors.white,
              border: Border.all(
                width: 0.5,
                color: const Color(0xFFEEEEEE),
              ),
              borderRadius: BorderRadius.circular(10),
              boxShadow: const [
                BoxShadow(
                  color: Color(0x30000000), // 阴影颜色
                  spreadRadius: 0, // 阴影扩散程度
                  blurRadius: 2, // 阴影模糊程度
                  offset: Offset(0, 2), // 阴影偏移量
                ),
              ],
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  children: [
                    Image.asset(
                      'assets/images/bt_icon_coin.png',
                      width: 37,
                      height: 37,
                    ),
                    Padding(
                        padding: const EdgeInsets.only(left: 9),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text('${item.exchangeCoin}',
                                style: const TextStyle(
                                    fontSize: 14, color: Color(0xFF523E0B), fontWeight: FontWeight.bold)),
                            Visibility(
                                visible: item.discount > 0,
                                child: Padding(
                                  padding: const EdgeInsets.only(top: 5),
                                  child: Text('${(item.discount * 100).toInt()}%off',
                                      style: const TextStyle(
                                          fontSize: 9,
                                          color: Color(0xFF3F5FCF),
                                          fontWeight: FontWeight.normal)),
                                ))
                          ],
                        )),
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Text('\$${item.price}',
                        style: const TextStyle(
                            fontSize: 18, color: Color(0xFF202020), fontWeight: FontWeight.bold)),
                    Visibility(
                        visible: item.price != item.originalPrice,
                        child: Padding(
                          padding: const EdgeInsets.only(left: 8),
                          child: Text('\$${item.originalPrice}',
                              style: const TextStyle(
                                  decoration: TextDecoration.lineThrough,
                                  fontSize: 10,
                                  color: Color(0x30000000),
                                  fontWeight: FontWeight.normal)),
                        ))
                  ],
                )
              ],
            ),
          ),
          Visibility(
            visible: (item.tags ?? '').isNotEmpty && item.tags != 'Hot',
            child: Positioned(
              top: 0,
              right: 0,
              child: Container(
                height: 20,
                width: 70,
                decoration: const BoxDecoration(
                    color: Color(0xFF4DB4FF),
                    borderRadius:
                        BorderRadius.only(bottomLeft: Radius.circular(10), topRight: Radius.circular(10))),
                child: Text(item.tags ?? '',
                    textAlign: TextAlign.center,
                    style: const TextStyle(
                        fontSize: 12, color: Color(0xFFFFFFFF), fontWeight: FontWeight.normal)),
              ),
            ),
          ),
          Visibility(
            visible: item.tags == 'Hot',
            child: Positioned(
              top: 0,
              right: 0,
              child: Image.asset(
                'assets/images/bt_hot_tag.png',
                width: 45,
                height: 20,
              ),
            ),
          )
        ],
      ),
      onTap: () async {
        //EasyLoading.show(status: 'Loading...');
        model.purchase(item, (success, msg, orderNo) {
          if (success) {
            //context.router.navigate(MiddleEntryRoute());
            context.router.navigate(PaySuccessRoute(coins: '${item.exchangeCoin}', orderNo: orderNo));
          } else {
            EasyLoading.showToast(msg);
          }
        });
      },
    );
  }
}
